baubs git
Commit 03e083b4a328b742e1a862d130aa076fff2d028c
Parents : 641bc04
Author : copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Date : 2025-12-28T08:41:49Z
feature: Add detailed documentation for RAF-based polling
Co-authored-by: jhbruhn <1036566+jhbruhn@users.noreply.github.com>
Changes
Diff
diff --git a/src/stores/useMachineStore.ts b/src/stores/useMachineStore.ts
index a8dc4c5..553b856 100644
--- a/src/stores/useMachineStore.ts
+++ b/src/stores/useMachineStore.ts
@@ -371,9 +371,16 @@ export const useMachineStore = create<MachineState>((set, get) => ({
};
// Track last poll time for throttling
+ // We use requestAnimationFrame for smooth UI updates but still need to
+ // respect polling intervals to avoid excessive API calls
let lastPollTime = 0;
// Main polling function using requestAnimationFrame
+ // Benefits over setTimeout:
+ // - Synchronized with browser refresh rate (typically 60fps)
+ // - Automatically paused when tab is not visible (better battery life)
+ // - Smoother animations and UI updates
+ // - More efficient rendering
const poll = async (timestamp: number) => {
// Check if enough time has passed since last poll
const interval = getPollInterval();
@@ -409,6 +416,7 @@ export const useMachineStore = create<MachineState>((set, get) => ({
const pollRafId = requestAnimationFrame(poll);
// Service count polling (every 10 seconds)
+ // Keep using setInterval for this as 10s is too long for RAF
const serviceCountIntervalId = setInterval(refreshServiceCount, 10000);
set({ pollRafId, serviceCountIntervalId });
Served by rngit 1.3.3 - Generated in 0.04s